#!/usr/bin/env python
# encoding: utf-8


from app.views.webapi import route_api
from  flask import request,jsonify,g
import requests,json,decimal

from app.common.libs.UploadService import UploadService

from app import app, db

@route_api.route("/upload/image",methods = [ "GET","POST" ])
def uploadImage():
    resp = { 'code':20000,'message':'上传成功~', 'data':{}}
    file_target = request.files
    file = file_target['file'] if 'file' in file_target else None
    if not file:
        resp['code'] = -1
        resp['message'] = "数据错误,file字段不存在"
        return jsonify( resp )
    resp = UploadService.uploadByImage(file)

    return jsonify( resp )

@route_api.route("/upload/file",methods = [ "GET","POST" ])
def uploadFile():
    resp = { 'code':20000,'message':'上传成功~', 'data':{}}
    file = request.files.get('file')
    resp = UploadService.uploadByFile(file)

    return jsonify( resp )

@route_api.route("/upload",methods = [ "GET","POST" ])
def upload():
    resp = { 'code':20000,'message':'上传成功~', 'data':{}}
    file_target = request.files
    file = file_target['file'] if 'file' in file_target else None
    if not file:
        resp['code'] = -1
        resp['message'] = "数据错误,file字段不存在"
        return jsonify( resp )

    resp = UploadService.uploadByFile(file)

    return jsonify( resp )

